//
//  GMTodayTaskCell.m
//  Teecloud
//
//  Created by 小熊 on 2018/7/4.
//  Copyright © 2018年 小熊. All rights reserved.
//

#import "GMTodayTaskCell.h"
#import "XZTaskModel.h"

@interface GMTodayTaskCell ()
@property (weak, nonatomic) IBOutlet UILabel *taskNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *awardScoreLabel;

@property (weak, nonatomic) IBOutlet UILabel *finishCountLabel;

@end
#define PerformColor [UIColor colorWithHexString:@"128B03" andAlpha:1.0f]
@implementation GMTodayTaskCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

-(void)setModel:(XZTaskModel *)model{
    _model = model;
    
    //任务名称
    //将分享xxx变成分享腾云教育
    if ([model.Name zj_isContainString:@"分享"]) {
         self.taskNameLabel.text = @"分享腾云教育";
    }else{
         self.taskNameLabel.text = model.Name;
    }
   
    
    //积分 学币奖励
    if ([model.CoinOffer isEqualToString:@"0"]) {
        self.awardScoreLabel.text = [NSString stringWithFormat:@"积分加+%@",model.ScoreOffer];
    }else{
        if ([model.Name isEqualToString:@"邀请注册"]) {
            NSString *integralStr = [NSString stringWithFormat:@"积分加+%@/用户,",model.ScoreOffer];
            
            NSString *awardScoreStr = [NSString stringWithFormat:@"%@学币+%@/用户",integralStr,model.CoinOffer];
            
            NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc] initWithString:awardScoreStr];
            
            //给富文本添加属性-字体颜色
            [attributedStr addAttribute:NSForegroundColorAttributeName
                                  value:[UIColor redColor]
                                  range:NSMakeRange(integralStr.length+2, model.CoinOffer.length+1)];
            
            //设置label的富文本属性
            self.awardScoreLabel.attributedText = attributedStr;
        }else{
            
            NSString *integralStr = [NSString stringWithFormat:@"积分加+%@,",model.ScoreOffer];
            
            NSString *awardScoreStr = [NSString stringWithFormat:@"%@学币+%@",integralStr,model.CoinOffer];
            
            NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc] initWithString:awardScoreStr];
            
            //给富文本添加属性-字体颜色
            [attributedStr addAttribute:NSForegroundColorAttributeName
                                  value:[UIColor redColor]
                    range:NSMakeRange(integralStr.length+2, model.CoinOffer.length+1)];
    
            //设置label的富文本属性
            self.awardScoreLabel.attributedText = attributedStr;
        }
    }
    
    /*完成情况标签*/
    if ([model.Name isEqualToString:@"邀请注册"]) {
        if (model.FinishedCount > 0) {
            NSString *str = @"已完成";
            NSString *finishCountStr = [NSString stringWithFormat:@"%ld",model.FinishedCount];
            NSString * finishStr = [NSString stringWithFormat:@"%@ %@/%ld",str,finishCountStr,model.FinishedMax];
            
            
            NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc] initWithString:finishStr];
            
            //给富文本添加属性-字体颜色
            [attributedStr addAttribute:NSForegroundColorAttributeName
                                  value:PerformColor
                                  range:NSMakeRange(0, 3)];
            [attributedStr addAttribute:NSForegroundColorAttributeName
                                  value:[UIColor redColor]
                                  range:NSMakeRange(3, finishCountStr.length+1)];
            //设置label的富文本属性
            self.finishCountLabel.attributedText = attributedStr;
        }else{
           self.finishCountLabel.text = [NSString stringWithFormat:@"已完成 %ld/%ld",model.FinishedCount,model.FinishedMax];
            self.finishCountLabel.textColor = [UIColor darkGrayColor];
        }
    }else{//其他项
        if (model.FinishedCount == 1) {
          self.finishCountLabel.text = @"已完成";
            self.finishCountLabel.textColor = PerformColor;
        }else{
        self.finishCountLabel.text = @"待完成";
        }
    }

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
